﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Common.Dao;

namespace Analyze.Manager
{
    public class StopWordManager
    {
        public HashSet<string> StopWords;
//        Regex numRegex = new Regex("[0-9]+"); //正则表达式 表示数字的范围 ^符号是开始，$是关闭   
        
        private static readonly object Lock = new object();

        private static StopWordManager _instance;


        public static StopWordManager GetInstance()
        {
            if (null == _instance)
            {
                lock (Lock)
                {
                    _instance = new StopWordManager();
                }
            }
            return _instance;
        }

        private StopWordManager()
        {
            StopWords = new HashSet<string>(StopWordDao.GetStopWord());
        }
            
        public bool IsStopWord(string word)
        {
            return StopWords.Any(m => m.EndsWith(word) || m.StartsWith(word)) /*|| numRegex.IsMatch(word)*/;
        }
        
//        public List<string> GetStopWord(List<string> words)
//        {
//            return StopWords.Any(m => m.EndsWith(word)) || numRegex.IsMatch(word);
//        }
    }
}